package com.demo.controller;

import com.demo.common.model.R;
import com.demo.entity.ClueRemark;
import com.demo.service.ClueRemarkService;
import com.demo.vo.ClueRemarkVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 线索备注接口
 */
@RestController
@RequestMapping("/api/clue/remark")
public class ClueRemarkController {
    @Autowired
    private ClueRemarkService clueRemarkService;

    /**
     * 根据线索标识分页查询线索备注列表
     */
    @GetMapping("/page")
    public R<PageInfo<ClueRemarkVo>> loadClueRemarkPage(@RequestParam Integer current,
                                              @RequestParam(required = false,defaultValue = "10") Integer pageSize,
                                              @RequestParam Integer clueId){
        PageInfo<ClueRemarkVo> pageInfo = clueRemarkService.queryClueRemarkListByPage(current,pageSize,clueId);
        return R.OK(pageInfo);
    }
    /**
     * 新增线索备注
     */
    @PostMapping
    public R<String> saveClueRemark(@RequestBody ClueRemark clueRemark){
        Boolean saved = clueRemarkService.saveClueRemark(clueRemark);
        return saved ? R.OK(null) : R.FAIL("新增线索备注失败");
    }
    /**
     * 根据标识嘻哈寻线索备注信息
     */
    @GetMapping("/info/{id}")
    public R<ClueRemark> loadClueRemark(@PathVariable Integer id){
        ClueRemark result = clueRemarkService.getById(id);
        return R.OK(result);
    }
    /**
     * 修改线索备注信息
     */
    @PutMapping
    public R<String> modifyClueRemark(@RequestBody ClueRemark clueRemark){
        Boolean result = clueRemarkService.updateClueRemark(clueRemark);
        return result ? R.OK(null) :R.FAIL("修改备注信息失败");
    }
    /**
     * 删除备注信息
     */
    @DeleteMapping("{id}")
    public R<String> delClueRemark(@PathVariable Integer id){
        Boolean delClue = clueRemarkService.removeClueRemark(id);
        return delClue ? R.OK(null) :R.FAIL("删除备注信息失败");
    }
}

